<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>唯爱薇o朝圣之路-课程</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <h1>唯爱薇o朝圣之路-组件实验</h1>
    <hr/>
    <div id="app">




    </div>
    
</body>
<script>
    const app = Vue.createApp({
            data() {

                return {
                    //---此处添加变量名称
                    courseName:'',
                    courses: []
                }
                
            },
            methods: {
                addCourse() {
                    this.courses.push(this.courseName)
                    this.courseName=""
                }
            },
            template: `<div>
                <input v-model="courseName" />
                <hr />
                <button v-on:click="addCourse">添加课程</button>
                <hr />
                <CourseTitle />
                <CourseList
                    v-for="(course,index) of courses"
                    v-bind:item="course"
                    v-bind:index="index"
                />
            </div>`,
        }
    )
    
    app.component("CourseTitle",{
        template: '<h1 style="text-align:center">Course课程列表</h1>'
    })
    app.component("CourseList",{
        //使用props接收父组件传递过来的参数
        props:["index","item"],
        template:`<li>[{{ index }}] -- {{ item }} </li>`,
    })
    app.mount("#app")

</script>
</html>